matplotlib handling colors
colormap
Matplotlib: colormap transformations — SciPy Cookbook documentation
Operating on color vectors, Operating on indices, Discrete colormap
https://scipy-cookbook.readthedocs.io/items/Matplotlib_ColormapTransformations.html
Matplotlib: loading a colormap dynamically — SciPy Cookbook documentation
https://scipy-cookbook.readthedocs.io/items/Matplotlib_Loading_a_colormap_dynamically.html
Matplotlib: show colormaps — SciPy Cookbook documentation
https://scipy-cookbook.readthedocs.io/items/Matplotlib_Show_colormaps.html
also "colormap has a break halfway through"
discrete colormap
code:python
import matplotlib as mpl
cmap = = mpl.colormaps'viridis'.resampled(8)
white center
code:python
from matplotlib.colors import ListedColormap
newcolors=[]
cmap=plt.cm.get_cmap('jet', 11)
for n in range(11):
if n==5:
newcolors.append(1.,1.,1.,1.)
else:
newcolors.append(cmap(n))
newcmap= ListedColormap(newcolors)
code:python
import matplotlib.colors as mcolors
cmap=mcolors.LinearSegmentedColormap.from_list("heatwave",'lightblue', 'yellow', 'orange', 'red', 'darkred',N=5)
matplotlibのcolormapのRGB情報取得と関連操作 - Qiita
https://qiita.com/HidKamiya/items/524d77e3b53a13849f1a
Specify color beyond limits
code:python
# no value
new_cmap=cmap.set_bad(color='black', alpha=None)
# larger than limit
new_cmap=cmap.set_over(color='black', alpha=None)
# lower than limit
new_cmap=cmap.set_under(color='black', alpha=None)¶
makeing colormap from 2 RGB values
code:python
# function
def two_color(low,high,name):
import matplotlib as mpl
LinL=np.hstack((low,high))
#print LinL
#LinL=np.array(0,127,235,255,255,0)
LinL=LinL/255.
s=len(LinL)
LinL=LinL.reshape((s/3,3))
N,n3=LinL.shape
rgb=np.zeros((3,N,3))
for n in range(3):
rgbn,:,0=np.linspace(0,1,N)
rgbn,:,1=LinL:,n
rgbn,:,2=LinL:,n
k='red', 'green', 'blue'
data=dict(zip(k,rgb)) # makes a dictionary from 2 lists
my_cmap = mpl.colors.LinearSegmentedColormap(name,data)
return my_cmap
# caling function
cmap=two_color(0,127,235,255,255,0,"cobaltblue-yellow")
pylab_examples example code: custom_cmap.py
Creating a colormap from a list of colors, valying alpha, Discrete
https://matplotlib.org/examples/pylab_examples/custom_cmap.html
python - Transparent colormap - Stack Overflow
https://stackoverflow.com/questions/8580631/transparent-colormap
MetPy Mondays `#119 - Custom Colormaps : Unidata Developer's Blog
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-119-custom-colormaps
matplotlib.colors.LinearSegmentedColormap.from_list("name",list,N=)
https://matplotlib.org/api/_as_gen/matplotlib.colors.LinearSegmentedColormap.html
MetPy Mondays `#158 - Custom Legends and Colormapped Lines : Unidata Developer's Blog
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-158-custom-legends
legend
MetPy Mondays `#177​​​ - Changing Figure Colors on a Skew-T : Unidata Developer's Blog
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-177-changing-figure
code:python
ax.set_facecolor("black")
fig.patch.set_facecolor("bisque")
2D colormaps
Pythology Blog: Designing 2D colormaps and using them with matplotlib
http://pythology.blogspot.com/2016/05/2d-colormaps-in-matplotlib.html
python - 2d hsv color space in matplotlib - Stack Overflow
https://stackoverflow.com/questions/10787103/2d-hsv-color-space-in-matplotlib
A color
check available color
code:python
print(matplotlib.colors.cnames)
Examples
Changing color of bars depending on El Nino or La Nina
https://nbviewer.jupyter.org/gist/tmiyama/3879d7b526d746a16d0663f700be2079/bar_example.ipynb
Colormap Examples (PyHOGS)
http://pyhogs.github.io/colormap-examples.html
Colormap example for bathymetry (PyHOGS)
http://pyhogs.github.io/colormap-bathymetry.html
See also
matplotlib colorbar
matplotlib better colormap
mixbox